package com.sgcc.pda.mdrh.zoom.router;

import android.content.Context;
import android.content.Intent;

import com.google.gson.Gson;
import com.sgcc.pda.baselibrary.utils.DeviceUtil;
import com.sgcc.pda.hzaidl.AIDLServiceImpl;
import com.sgcc.pda.hzaidl.IHZAidlCallback;
import com.sgcc.pda.hzaidl.entity.RequestBean;
import com.sgcc.pda.mdrh.app.ZoomApplication;
import com.sgcc.pda.mdrh.ui.activity.VideoPlayActivity;
import com.sgcc.pda.model.business.request.GetSharedPreferenceRequest;
import com.sgcc.pda.model.business.request.PlayVideoRequest;
import com.sgcc.pda.sdk.utils.db.ContentProviderUtil;

/**
 * Created by zh on 2020/8/10.
 * 业务功能接口router
 */
public class BusinessRouter extends BaseOperateRouter {


    @Override
    public String handleResult(Context context, RequestBean requestBean, final CompleteListener completeListener) {
        try {

            String methodName = requestBean.getMethodName();
            switch (methodName) {
                // 获取权限信息
                case "getIsAuthorInfo":
                    /*TODO
                    AppBaseInfoModel appBaseInfoModel = new AppBaseInfoModel();
                    List<AppBaseInfo> appBaseInfos = appBaseInfoModel.queryAll();
                    ArrayList<PermissionInfo> permissionInfoList = new ArrayList<>();
                    PermissionInfo permissionInfo;
                    if (null != appBaseInfos && !appBaseInfos.isEmpty()){
                        for(AppBaseInfo baseInfo : appBaseInfos){
                            permissionInfo = new PermissionInfo();
                            permissionInfo.setPackageName(baseInfo.getAppPackage());
                            permissionInfo.setAppName(baseInfo.getAppName());
                            String orderType = TaskConstant.mapTaskCode.get(baseInfo.getAppPackage());
                            permissionInfo.setOrderType(TextUtils.isEmpty(orderType) ? "" : orderType);
                            permissionInfoList.add(permissionInfo);
                        }
                    }
                    return new Gson().toJson(permissionInfoList);*/
                    // 退出登录
                case "logOut":
//                    HomeBusi.getInstance().exit(context);
                    break;

                case "getSharedPreference":
                    String paramJson = requestBean.getParamJson();
                    GetSharedPreferenceRequest request =
                            new Gson().fromJson(
                                    paramJson,
                                    GetSharedPreferenceRequest.class);
                    return ContentProviderUtil.getSharepreferenceValue(
                            context,
                            request.getEditorKey(),
                            request.getKey());
                case "playVideo":
                    PlayVideoRequest playVideoRequest = new Gson().fromJson(requestBean.getParamJson(), PlayVideoRequest.class);
                    Intent intent = new Intent(ZoomApplication.getInstance().getTopActivity(), VideoPlayActivity.class);
                    intent.putExtra("url", playVideoRequest.getUrl());
                    ZoomApplication.getInstance().getTopActivity().startActivity(intent);
                    break;
                // 获取设备唯一标识
                case "getIMEI":
                    return DeviceUtil.getDeviceIMEI(context);
                case "getToastInfo":
                    AIDLServiceImpl.getInstance().post(
                            requestBean.getParamJson(),
                            new IHZAidlCallback.Stub() {
                                @Override
                                public void callback(String result) {
                                    completeListener.complete(1, result);
                                }
                            }
                    );
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return null;
    }


}
